package site.lyweb.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import site.lyweb.domain.dto.PageDTO;
import site.lyweb.domain.dto.StuCourseRelation;
import site.lyweb.domain.dto.CourseScoreDTO;
import site.lyweb.domain.query.CourseScoreQuery;
import site.lyweb.result.RestResult;
import site.lyweb.service.CourseScoreService;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * @Author 林瑶
 * @Description TODO
 * @Date 2024/6/20 2:21
 */
@CrossOrigin(origins = "*")
@RestController
@Tag(name="学生成绩管理模块")
@Slf4j
@RequestMapping("/course_score")
public class CourseScoreController {
    @Resource
    private CourseScoreService courseScoreService;
    /**
     * 分页查询学生成绩管理数据
     *
     * @return
     */

    @Operation(summary = "分页查询学生成绩管理数据")
    @GetMapping(value = "/course_score_info/getCourseScoreByPage")
    public RestResult getCourseScoreByPage( CourseScoreQuery courseScoreQuery) {


        //分页查询的结果用PageDTO进行封装
        PageDTO<CourseScoreDTO> pageDTO = courseScoreService.getCourseScoreByPage(0, courseScoreQuery);

        //有的时候，查询可以不判断成功与失败，不管查没查到数据，都返回200，页面上去控制显示
        return RestResult.SUCCESS(pageDTO);
    }

    @Operation(summary = "修改学生成绩")
    @PostMapping(value = "/course_score_info/updateCourseScore")
    public RestResult updateCourseScore(StuCourseRelation stuCourseRelation){
        String id = stuCourseRelation.getId();
        BigDecimal courseScore = stuCourseRelation.getCourseScore();
        return courseScoreService.updateCourseScore(id,courseScore)?RestResult.SUCCESS("成绩修改成功！"):RestResult.FAIL();
    }


}
